﻿<%@ page language="C#" masterpagefile="MasterPageFrame.master" autoeventwireup="true" inherits="admin_cardlist, App_Web_bgx0xzll" title="卡管理 -> 卡列表" %>
<%@ Register Src="../WebUserControl/PageNavigation.ascx" TagName="PageNavigation"
    TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .pic{width:50px}
        td.sortnum{width:80px}
        input.sortnum{width:30px;font-size:8pt;font-family:Arial;text-align:right}
        #productTypeID{width:180px}
        .tf{width:50px}
        
        #state{width:120px}
        #cardtypeid{width:300px}
        
        .cardnum{font-family:Verdana}
        
        .state{color:#ffffff;display:inline-block;padding:2px}
        .s_1{background-color:#ff0000}
        .s0{background-color:#999999}
        .s1{background-color:#CCFF33;color:#009900}
        .s2{background-color:#99CC00}
        .s3{background-color:#009900}
        .s4{background-color:#0066FF}
        
        #divmoresearch{display:none}
        
        #iframecardfahuo{width:100%;height:550px}
        #frame0{width:100%;height:550px}
    </style>
    <script type="text/javascript">
        function __export()
        {
            window.open("cardlistexport.aspx");
        }
    
        function __modify(__productid)
        {
            document.location="productpub.aspx?productid="+__productid+"&urlhref="+escape(location);
        }

        function __batch_delete() {
            var r = $form.getCheckboxValue("cardid");
            if (!r) {
                alert("请选择要删除的卡记录");
                return false;
            }
            if (confirm("您真的要删除选中的卡记录吗？")) {
                
                document.location = "carddelete.aspx?batchcardid=" + r + "&urlhref=" + escape(location);
            }
        }
        window.onload = function() {

            $form.addOption("cardtypeid", "", "所有");
            $form.addOptionsByXML("xmlcardtype.aspx", "cardtypeid", "cardtypeid", "cardtypename");


            var i;
            var v;
            $form.addOption("state", "", "所有");
            for (i = 0; i <= 4; i++) {
                $form.addOption("state", i, $card.state2text(i));
            }

            $("span.state").each(function() {
                if ($(this).text() == "1") {
                    v = DateDiff($(this).attr("activationtime"), "<%=DateTime.Now.ToString()%>");
                    if (v><%=core.setting.get("cardtimeout") %>)
                    {
                        $(this).text("已激活,但已经失效"+v+"天");
                    }
                    else
                    {
                        $(this).text($card.state2text($(this).text()));
                    }
                }
                else {
                    $(this).text($card.state2text($(this).text()));
                }
            });
            
            $("span.cardattr").each(function() {
                if ($(this).text() == "0") {
                    $(this).html("<span style=\"color:red\">未激活</span>");
                }
                else {
                    $(this).html("<span style=\"color:green\">已激活</span>");
                }
            });
            
            $form.setdataByUrl("searchform");
            
            return;
            $("a.jxsid").each(function() {
                if ($(this).text() != "") {
                    $ajax.load({url:"xmljxs.aspx",data:"json=json&jxsid="+$(this).text(),type:"json",method:"get"});
                    $(this).text($ajax.responseJson[0].jxsloginname);
                }
            });
        }



        //============================

        $(document).ready(function() {
            if (getCookie("cardlist_moresearch") == "true") {
                $("#divmoresearch").show();
                $("#btnmoresearch").text("切换到简单搜索模式");
            }
            else {
                $("#divmoresearch").hide();
                $("#btnmoresearch").text("切换到高级搜索模式");

            }

            $("#submittime0,#submittime1,#activationtime0,#activationtime1,#expresstime0,#expresstime1").datepicker({ monthNamesShort: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'], changeYear: true, changeMonth: true, dateFormat: 'yy-m-d' });


            $("span.opa").each(function() {
                if ($(this).attr("state") == "0" && "<%=Session["flagcardjihuo"]%>"=="True") {
                    $(this).html("<a href=\"javascript:__jihuo(" + $(this).attr("cardid") + ");\">激活</a>");
                }
                if ($(this).attr("state") == "1" && "<%=Session["flagcardjihuo"]%>"=="True") {
                    $(this).html("<a href=\"javascript:__jihuocancel(" + $(this).attr("cardid") + ");\">取消激活</a>");
                }
                if ($(this).attr("state")=="2" && "<%=Session["flagcardotherstate"]%>"=="True") {
                    $(this).html("<a href=\"javascript:__fahuo(" + $(this).attr("cardid") + ");\">修改状态</a>");
                }
                if (($(this).attr("state") == "3" || $(this).attr("state") == "4") && "<%=Session["flagcardotherstate"]%>"=="True") {
                    $(this).html("<a href=\"javascript:__fahuo(" + $(this).attr("cardid") + ");\">修改状态</a>");
                }
            });

            $("span.cardid").each(function() {
                if ($(this).attr("state")=="0") {
                    $(this).html("<input type=\"checkbox\" name=\"cardid\" value=\""+$(this).attr("cardid")+"\" cardnum=\"cardnum\"/>");
                }
            });         
            
        });
        function __moresearch() {

            if (getCookie("cardlist_moresearch")=="true") {
                $("#divmoresearch").hide();
                setCookie("cardlist_moresearch", "false");
                $("#btnmoresearch").text("切换到高级搜索模式");
            }
            else {
                $("#divmoresearch").show();
                setCookie("cardlist_moresearch", "true");
                $("#btnmoresearch").text("切换到简单搜索模式");
            }
        }
        
        function __batch_jihuo()
        {
            var v=$form.getCheckboxValue("cardid");
            if(v=="")
            {
                alert("请选择要激活的卡");
                return;
            }
            __jihuo(v);
        }

        function __jihuo(_cardid) {
            $("#cardid2").val(_cardid);
            document.getElementById("frame0").contentWindow.document.location = "jxsselector.aspx";

            $('#dialogjxs').dialog({
                autoOpen: false,
                width: 800,
                resizable: false,
                modal: true,
                title: "选择经销商"
            });

            $('#dialogjxs').dialog('open');
        }
        
        
        function __jihuocancel(_cardid)
        {
            if(confirm("您真的要取消激活该卡吗？"))
            {
                location="cardjihuocancel.aspx?cardid="+_cardid+"&urlhref="+escape(location);
            }
            
        }
        
        function __jihuo_action(_cardid) {
            //location = "cardjihuobysystemjxs.aspx?cardid=" + _cardid + "&urlhref=" + escape(location);
            var r = (document.getElementById("frame0").contentWindow.$form.getRadioValue("jxsid"));
            if (r == "") {
                alert("请选择经销商");
                return;
            }
            $("#byjxsid").val(r);
            var elems=document.getElementById("frame0").contentWindow.document.getElementsByName("jxsid");
            var i;
            var jxscompanyname;
            for(i=0;i<elems.length;i++)
            {
                if(elems[i].checked)
                {
                    jxscompanyname = elems[i].getAttribute("jxscompanyname");
                    //alert(jxsloginname);
                    break;
                }
                
            }
            if (confirm("确认使用经销商“" + jxscompanyname + "”激活此卡吗？"))
            {
                location = "cardjihuo.aspx?jxsid=" + $("#byjxsid").val() + "&cardid=" + $("#cardid2").val() + "&urlhref=" + escape(location);
            }
    
        }

        function __fahuo(_cardid) {
            document.getElementById("iframecardfahuo").contentWindow.document.location = "cardfahuo.aspx?cardid=" + _cardid;

            $('#dialogCard').dialog({
                autoOpen: false,
                width: 680,
                resizable: false,
                modal: true,
                title: "状态修改"
            });

            $('#dialogCard').dialog('open');
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <form method="get" id="searchform">
        <fieldset><legend>搜索</legend>
            <table>
                <tr>
                    <td>卡状态<select id="state" name="state"></select>
                    </td>
                    <td>卡属性<select id="cardattr" name="cardattr"><option value="">所有</option><option value="0">未激活</option><option value="1">已激活</option></select>
                    </td>
                    <td>卡分类<select id="cardtypeid" name="cardtypeid"></select>
                    </td>
                    <td>卡号<input type="text" name="cardnum" id="cardnum" style="width:100px"/>
                    </td>
                    <td>
                        <input type="submit" value="搜索" name="btnsubmit" />
                    </td>
                    <td>
                        <a id="btnmoresearch" href="javascript:__moresearch();">切换到高级搜索模式</a>
                    </td>
                </tr>
            </table>
            <div id="divmoresearch">
                <table>
                    <tr>
                        <td>提货人姓名<input type="text" name="truename" id="truename"/></td>
                        <td>经销商编号<input type="text" name="jxsloginname" id="jxsloginname"/></td>
                        <td></td>
                    </tr>
                </table>
                <table>
                    <tr>
                        <td>提货时间范围:从<input type="text" name="submittime0" id="submittime0" class="inputdate"/>至<input type="text" name="submittime1" id="submittime1" class="inputdate"/></td>
                        <td>激活时间范围:从<input type="text" name="activationtime0" id="activationtime0" class="inputdate"/>至<input type="text" name="activationtime1" id="activationtime1" class="inputdate"/></td>
                        <td>发货时间范围:从<input type="text" name="expresstime0" id="expresstime0" class="inputdate"/>至<input type="text" name="expresstime1" id="expresstime1" class="inputdate"/></td>
                    </tr>
                </table>
            </div>
        </fieldset>
    </form>
    <div id="pagelist1" runat="server"></div>
    <uc1:PageNavigation id="PageNavigation1" runat="server">
    </uc1:PageNavigation>
    <fieldset><legend>批操作</legend>
        <div class="buttons">
            <div runat="server" id="batchAction" visible="false">
                <input type="button" value="全选" onclick="javascript:$form.checkboxSelect('cardid',true);"/>
                <input type="button" value="全不选" onclick="javascript:$form.checkboxSelect('cardid',false);"/>
                <input type="button" value="反选" onclick="javascript:$form.checkboxReverse('cardid');"/>
                <input type="button" value="批量彻底删除" onclick="javascript:__batch_delete();"/>
                <input type="button" value="批量激活" onclick="javascript:__batch_jihuo();"/>
            </div>
            <input type="button" value="把当前查询结果导出成excell" onclick="javascript:__export();"/>
        </div>
    </fieldset>
    <div id="dialogCard" class="X-dialog">
        <iframe src="" id="iframecardfahuo" frameborder="0"></iframe>
    </div>
    <div id="dialogjxs" class="X-dialog">
        <iframe src="" id="frame0" frameborder="0"></iframe>
        <input type="hidden" name="cardid2" id="cardid2" />
        <input type="hidden" name="byjxsid" id="byjxsid" />
        <div class="center"><input type="button" value="激活此卡" onclick="javascript:__jihuo_action();"/></div>
    </div>
</asp:Content>

